package com.wlscale.roadsystem.modular.setting.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.wlscale.roadsystem.R;

public class AxisNumberCorrectAdapter extends RecyclerView.Adapter<AxisNumberCorrectAdapter.CarTypeItemHolder> {

    private Context mContext;

    public AxisNumberCorrectAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int getItemCount() {
        return 23;
    }

    @NonNull
    @Override
    public AxisNumberCorrectAdapter.CarTypeItemHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
        return new AxisNumberCorrectAdapter.CarTypeItemHolder(LayoutInflater.from(mContext).inflate(R.layout.item_axis_number_correct, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull AxisNumberCorrectAdapter.CarTypeItemHolder carTypeItemHolder, int i) {
        int carType = getCarTypeImage(i);//车型
        int axisType = getAxisTypeImage(i);//轴型
        carTypeItemHolder.iv_cartype_image.setImageResource(carType);
        carTypeItemHolder.iv_axis_type_image.setImageResource(axisType);

    }

    /**
     * 获取车型图片
     *
     * @param i
     */
    private int getCarTypeImage(int i) {
        int carType = 0;
        if (i == 0) {
            carType = R.mipmap.cartype_2;
        } else if (i == 1) {
            carType = R.mipmap.cartype_3_1;
        } else if (i == 2) {
            carType = R.mipmap.cartype_3_2;
        } else if (i == 3) {
            carType = R.mipmap.cartype_3_3;
        } else if (i == 4) {
            carType = R.mipmap.cartype_3_4;
        } else if (i == 5) {
            carType = R.mipmap.cartype_4_1;
        } else if (i == 6) {
            carType = R.mipmap.cartype_4_2;
        } else if (i == 7) {
            carType = R.mipmap.cartype_4_3;
        } else if (i == 8) {
            carType = R.mipmap.cartype_4_4;
        } else if (i == 9) {
            carType = R.mipmap.cartype_4_5;
        } else if (i == 10) {
            carType = R.mipmap.cartype_5;
        } else if (i == 11) {
            carType = R.mipmap.cartype_5_1;
        } else if (i == 12) {
            carType = R.mipmap.cartype_5_1_1;
        } else if (i == 13) {
            carType = R.mipmap.cartype_5_1_2;
        } else if (i == 14) {
            carType = R.mipmap.cartype_5_1_3;
        } else if (i == 15) {
            carType = R.mipmap.cartype_5_1_4;
        } else if (i == 16) {
            carType = R.mipmap.cartype_5_2;
        } else if (i == 17) {
            carType = R.mipmap.cartype_5_3;
        } else if (i == 18) {
            carType = R.mipmap.cartype_6_1;
        } else if (i == 19) {
            carType = R.mipmap.cartype_6_2;
        } else if (i == 20) {
            carType = R.mipmap.cartype_6_3;
        } else if (i == 21) {
            carType = R.mipmap.cartype_6_4;
        } else if (i == 22) {
            carType = R.mipmap.cartype_n;
        }
        return carType;
    }

    /**
     * 获取轴型图片
     *
     * @param i
     */
    private int getAxisTypeImage(int i) {
        int axisType = 0;
        if (i == 0) {
            axisType = R.mipmap.axistype_2;
        } else if (i == 1) {
            axisType = R.mipmap.axistype_3_1;
        } else if (i == 2) {
            axisType = R.mipmap.axistype_3_2;
        } else if (i == 3) {
            axisType = R.mipmap.axistype_3_3;
        } else if (i == 4) {
            axisType = R.mipmap.axistype_3_4;
        } else if (i == 5) {
            axisType = R.mipmap.axistype_4_1;
        } else if (i == 6) {
            axisType = R.mipmap.axistype_4_2;
        } else if (i == 7) {
            axisType = R.mipmap.axistype_4_3;
        } else if (i == 8) {
            axisType = R.mipmap.axistype_4_4;
        } else if (i == 9) {
            axisType = R.mipmap.axistype_4_5;
        } else if (i == 10) {
            axisType = R.mipmap.axistype_5_1;
        } else if (i == 11) {
            axisType = R.mipmap.axistype_5_1_1;
        } else if (i == 12) {
            axisType = R.mipmap.axistype_5_1_2;
        } else if (i == 13) {
            axisType = R.mipmap.axistype_5_1_3;
        } else if (i == 14) {
            axisType = R.mipmap.axistype_5_1_4;
        } else if (i == 15) {
            axisType = R.mipmap.axistype_5_2;
        } else if (i == 16) {
            axisType = R.mipmap.axistype_5_3;
        } else if (i == 17) {
            axisType = R.mipmap.axistype_6_1;
        } else if (i == 18) {
            axisType = R.mipmap.axistype_6_2;
        } else if (i == 19) {
            axisType = R.mipmap.axistype_6_3;
        } else if (i == 20) {
            axisType = R.mipmap.axistype_6_4;
        } else if (i == 21) {
            axisType = R.mipmap.axistype_6_5;
        } else if (i == 22) {
            axisType = R.mipmap.axistype_n;
        }
        return axisType;
    }


    class CarTypeItemHolder extends RecyclerView.ViewHolder {
        /**
         * 车型图片
         */
        private ImageView iv_cartype_image;
        /**
         * 车轴图片
         */
        private ImageView iv_axis_type_image;

        public CarTypeItemHolder(@NonNull View itemView) {
            super(itemView);
            iv_cartype_image = itemView.findViewById(R.id.iv_cartype_image);
            iv_axis_type_image = itemView.findViewById(R.id.iv_axis_type_image);
        }
    }
}
